<template>
  <div>
    <Loading v-if="detailMovie.length==0"></Loading>
    <div v-else class="container" :style="{'background':detailMovie.backgroundColor}">
      <van-nav-bar
        title="电影详情"
        class="del_title"
        :style="{'background':detailMovie.backgroundColor}"
      >
        <template #left>
          <van-icon name="arrow-left" size="20" @click="back" />
        </template>
      </van-nav-bar>

      <div class="crumbs-nav">
        <a>猫眼电影 &nbsp; > &nbsp;</a>
        {{detailMovie.nm}}
      </div>

      <div class="movie-info-top">
        <div class="info-top_left">
          <img :src="detailMovie.img | imgfilter" />
        </div>
        <div class="info-top_right">
          <div>
            <h1>{{detailMovie.nm}}</h1>
          </div>
          <div class="sp2">{{detailMovie.enm}}</div>
          <div class="sp2">{{detailMovie.cat}}</div>
          <div class="sp2">{{detailMovie.dir}}</div>
          <div class="sp2">{{detailMovie.pubDesc}}/{{detailMovie.dur}}分钟</div>
          <div class="btn">
            <button>
              <i class="iconfont icon-xin"></i>想看
            </button>
            <button>
              <i class="iconfont icon--wujiaoxing"></i>看过
            </button>
          </div>
        </div>
      </div>

      <div class="real">
        <div class="hot_title">
          <i class="iconfont icon-koubei"></i>实时口碑
        </div>
        <div class="hot">
          <i>{{detailMovie.wish}}</i>人想看
        </div>
      </div>

      <div class="info">
        <div class="info_title">
          <span>简介</span>
          <span class="tit_right">
            展开
            <i
              @click="isActive=!isActive"
              :class="isActive?'iconfont icon-zhankai1':'iconfont icon-shouqi'"
            ></i>
          </span>
        </div>
        <div :class="isActive?'content':''">{{detailMovie.dra}}</div>
      </div>

      <!-- 剧照 -->
      <div class="Stills">
        <div class="photo_title">
          <div>剧照</div>
          <div class="title_right">
            <span>全部</span>
            {{detailMovie.photos!== undefined && detailMovie.photos!== null && detailMovie.photos.length>0
            ? detailMovie.photos.length: ''}}张
            <i
              class="iconfont icon-right"
              @click="photoList"
            ></i>
          </div>
        </div>
        <div class="info_bottom">
          <SwiperSlide>
            <div
              class="swiper-slide swiper_box" v-for="(item,index) in photoArr" :key="item.id">
              <img :src="item" @click="sceneImg(photoArr,index)" />
            </div>
          </SwiperSlide>
        </div>
      </div>
      <div class="bootom_btn" :style="{'background':detailMovie.backgroundColor}">
        <button>立即购票</button>
      </div>

      <MyPhoto v-show="isPhotoShow">
        <van-nav-bar title="剧照" :style="{'background':detailMovie.backgroundColor}">
          <template #left>
            <van-icon name="arrow-left" size="20" @click="backdetail" />
          </template>
        </van-nav-bar>
        <div class="photo_cnt">
          <div class="cnt_item" v-for="item in detailMovie.photos" :key="item.id">
            <img :src="item | imgfilter" />
          </div>
        </div>
      </MyPhoto>
    </div>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
import axios from "axios";
import SwiperSlide from "../../components/DetilSwiper/PhotosSwiper";
import MyPhoto from "./photolist";
import Loading from '../../components/Loading/loading'
export default {
  components: {
    SwiperSlide,
    MyPhoto,
    Loading,
  },
  data() {
    return {
      id: 0,
      detailMovie: [],
      isActive: true,
      isPhotoShow: false,
      photoArr:Array,
    };
  },

  mounted() {
    this.id = this.$route.params.id;
    axios.get("/ajax/detailmovie?movieId=" + this.id).then((res) => {
      //console.log(res.data.detailMovie);
      this.detailMovie = res.data.detailMovie;
      //console.log(this.detailMovie);
      var imgs = []
      this.detailMovie.photos.forEach(element => {
        this.photoArr = (element.replace("w.h", "85.115"))
        imgs.push(this.photoArr)
      });
        //console.log(imgs)
        this.photoArr = imgs;
        //console.log(this.photoArr)

    });
  },

  methods: {
    back() {
      this.$router.go(-1);
    },
    photoList() {
      this.isPhotoShow = true;
    },
    backdetail() {
      this.isPhotoShow = false;
    },
    sceneImg(images, index) {
      ImagePreview({
        images: images,
        showIndex: true,
        loop: false,
        startPosition: index,
      });
    },
  },

  created() {
    this.$bus.$emit("FooterBar", false);
    this.$bus.$emit("NavBar", false);
  },
  beforeDestroy() {
    this.$bus.$emit("FooterBar", true);
    this.$bus.$emit("NavBar", true);
  },
};
</script>

<style lang="scss" scoped>
/deep/ .van-nav-bar__title,
.van-ellipsis {
  color: #ffffff;
  font-size: 18px;
}

/deep/ .van-nav-bar {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1;
  width: 100%;
}
.container {
  width: 100%;
  .crumbs-nav {
    margin-top: 46px;
    padding: 15px;
    font-size: 14px;
    color: white;
  }
  .movie-info-top {
    
    overflow: hidden;
    display: flex;
    justify-content: flex-start;
    padding: 0 15px 15px 15px;
    color: #ffffff;

    .info-top_left {
      width: 28%;
      img {
        width: 100%;
      }
    }
    .info-top_right {
      width: 65%;

      font-size: 12px;
      line-height: 20px;
      margin-left: 5%;
      text-overflow: ellipsis;
      white-space: nowrap;
      h1 {
        color: white;
        font-weight: bold;
        font-size: 20px;
        line-height: 35px;
      }
      .btn {
        display: flex;
        flex: 1;
        justify-content: space-between;
        margin: 5px auto;
        height: 30px;
      }
      button {
        width: 48%;
        height: 100%;
        background: hsla(0, 0%, 100%, 0.35);
        box-sizing: border-box;
        border: none;
        border-radius: 5px;
        i {
          font-size: 12px;
          margin-right: 5px;
        }
      }
      .sp2 {
        opacity: 0.6;
      }
    }
  }
}
.real {
  overflow: hidden;
  margin: 15px;
  padding: 15px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;

  .hot_title {
    font-size: 12px;
    i {
      font-size: 12px;
      margin-right: 5px;
    }
  }
  .hot {
    text-align: center;
    height: 100px;
    line-height: 100px;
    i {
      color: yellow;
      font-weight: bold;
      font-size: 20px;
      line-height: 35px;
      margin-right: 5px;
    }
  }
}
.info {
  color: white;
  padding: 15px;
  font-size: 15px;
  line-height: 22px;
  .info_title {
    display: flex;
    flex: 1;
    justify-content: space-between;
    line-height: 40px;
    .tit_right {
      opacity: 0.6;
      font-size: 12px;
      i {
        padding: 3px;
        font-size: 12px;
      }
    }
  }
  .content {
    height: 66px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
}

.Stills {
  padding-bottom: 15px;
}
.photo_title {
  padding: 0 15px;
  display: flex;
  flex: 1;
  justify-content: space-between;
  line-height: 40px;
  color: white;
  .title_right {
    opacity: 0.6;
    font-size: 12px;
    i {
      font-size: 12px;
      margin-left: 2px;
    }
    span {
      margin: 0 1px;
    }
  }
}
.info_bottom {
  padding: 0 15px;
  margin-bottom: 50px;
}
.swiper_box {
  width: 100%;
  height: 100px;
  img {
    width: 100%;
    height: 100px;
  }
}

.bootom_btn {
  width: 100%;
  height: 50px;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 258;
  button {
    width: 90%;
    height: 40px;
    background: #ff5f16;
    border-radius: 8px;
    box-sizing: border-box;
    border: none;
    display: block;
    margin: 0 auto;
    color: #ffffff;
  }
}

.photo_cnt {
  width: 100%;
  height: 100%;
  margin-top: 50px;
  .cnt_item {
    width: 22%;
    height: 90px;
    padding: 1%;
    img {
      width: 100%;
      height: 100%;
    }
    float: left;
  }
}
</style>
